package com.wn.sk.product.controller;


import com.wn.common.api.Result;
import com.wn.sk.feign.dto.OrderPayDto;
import com.wn.sk.product.entity.vo.PaymentVo;
import com.wn.sk.product.service.IPromotionSeckillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 秒杀活动表 前端控制器
 * </p>
 *
 * @author yellow docker
 * @since 2022-11-07
 */
@Api(tags = "秒杀互动订单操作")
@RestController
@RequestMapping("/promotion-seckill")
public class PromotionSeckillController {

    @Autowired
    private IPromotionSeckillService promotionSeckillService;

    @PostMapping("/auth/order/confirm")
    @ApiOperation("确认订单")
    public Result<PaymentVo> confirmOrder(@RequestBody OrderPayDto orderPayDto, HttpServletRequest httpServletRequest){

        // 获取头信息中的 useId
        String userId = httpServletRequest.getHeader("userId");

        //RequestContextHolder  持有上下文的Request容器

//        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        String userId = requestAttributes.getRequest().getHeader("userId");

        Result<PaymentVo> result =  promotionSeckillService.confirmeOrder(orderPayDto,userId);
        return result;
    }

    //订单付款
    @ApiOperation("订单付款")
    @PostMapping("/auth/pay")
    public Result<String> payOrder(@RequestBody OrderPayDto orderPayDto){

       return promotionSeckillService.payOrder(orderPayDto);
    }

}

